package com.example.demo.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.dto.Gkhomeworkorder.GkhomeworkorderQueryRequest;
import com.example.demo.entity.Gkhomeworkorder;
import com.example.demo.service.GkhomeworkorderService;
import com.example.demo.dao.GkhomeworkorderMapper;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author darling
* @description 针对表【gkhomeworkorder】的数据库操作Service实现
*
*/
@Service
public class GkhomeworkorderServiceImpl extends ServiceImpl<GkhomeworkorderMapper, Gkhomeworkorder>
    implements GkhomeworkorderService{

    @Override
    public QueryWrapper<Gkhomeworkorder> getQueryWrapper(GkhomeworkorderQueryRequest gkhomeworkorderQueryRequest) {
        Integer id = gkhomeworkorderQueryRequest.getId();
        String number = gkhomeworkorderQueryRequest.getNumber();
        String outTradeNo = gkhomeworkorderQueryRequest.getOutTradeNo();
        Integer gkhomeworkid = gkhomeworkorderQueryRequest.getGkhomeworkid();
        Integer userid = gkhomeworkorderQueryRequest.getUserid();
        String username = gkhomeworkorderQueryRequest.getUsername();
        String gkhomeworkname = gkhomeworkorderQueryRequest.getGkhomeworkname();
        Integer price = gkhomeworkorderQueryRequest.getPrice();
        Date createtime = gkhomeworkorderQueryRequest.getCreatetime();
        Integer type = gkhomeworkorderQueryRequest.getType();
        String state = gkhomeworkorderQueryRequest.getState();
        String sortField = gkhomeworkorderQueryRequest.getSortField();
        String sortOrder = gkhomeworkorderQueryRequest.getSortOrder();
        QueryWrapper<Gkhomeworkorder> queryWrapper = new QueryWrapper<>();
        //精确查询
        queryWrapper.eq(ObjectUtils.isNotEmpty(id), "id", id);
        queryWrapper.eq(ObjectUtils.isNotEmpty(number), "number", number);
        queryWrapper.eq(ObjectUtils.isNotEmpty(outTradeNo), "outTradeNo", outTradeNo);
        queryWrapper.eq(ObjectUtils.isNotEmpty(gkhomeworkid), "gkhomeworkid", gkhomeworkid);
        queryWrapper.eq(ObjectUtils.isNotEmpty(userid), "userid", userid);
        queryWrapper.eq(ObjectUtils.isNotEmpty(price), "price", price);
        queryWrapper.eq(ObjectUtils.isNotEmpty(createtime), "createtime", createtime);
        queryWrapper.eq(ObjectUtils.isNotEmpty(type), "type", type);
        queryWrapper.eq(ObjectUtils.isNotEmpty(state), "state", state);

        //模糊查询
        queryWrapper.like(ObjectUtils.isNotEmpty(username), "username", username);
        queryWrapper.like(ObjectUtils.isNotEmpty(gkhomeworkname), "gkhomeworkname", gkhomeworkname);

        //排序规则
        queryWrapper.orderBy(ObjectUtils.isNotEmpty(sortField), sortOrder.equals("ascend"), sortField);


        return queryWrapper;
    }
}




